package com.itheima.parse;

import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class ParseDemo {
    public static void main(String[] args) throws DocumentException {
        SAXReader saxReader = new SAXReader();
        Document read = saxReader.read(new File("Day17_xml\\xml\\student.xml"));
        Element rootElement = read.getRootElement();
        List<Element> elements = rootElement.elements();
        ArrayList<User> alu = new ArrayList<>();
        for (Element element : elements) {
           /* Attribute id = element.attribute("id");
            String value = id.getValue();*/
            String id = element.attributeValue("id");
            /*Element element1name = element.element("name");
            String nameText = element1name.getText();*/
            String name = element.elementText("name");
            /*Element element1password = element.element("password");
            String passwordText = element1password.getText();*/
            String password = element.elementText("password");
            User user = new User(id,password,name);
            alu.add(user);
        }
        for (User user : alu) {
            System.out.println(user);
        }
    }
}
